import dayjs from "dayjs";
export default function (
  rawData,
  tags,
  begTime,
  interval = 4,
  extended = false
) {
  let format = "YYYY-MM-DD HH:mm:ss";
  let taggedData = new Array();
  let timestamp = new Date(begTime).getTime();
  for (let i = 0; i < rawData.length; i++) {
    let moment = dayjs(timestamp).format(format);
    let cell = new Array();
    for (let j = 0; j < tags.length; j++) {
      let airport = "OTHER";
      let type = "OTHER";
      let point = "OTHER";
      let tagArr = [];
      if (extended) {
        tagArr = tags[j].split("_");
        if (tagArr.length == 3) {
          airport = tagArr[0];
          type = tagArr[1];
          point = tagArr[2];
        }
        cell.push({
          airport,
          type,
          point,
          tag: tags[j],
          value: rawData[i][j],
        });
      } else {
        cell.push({
          tag: tags[j],
          val: rawData[i][j],
        });
      }
    }
    taggedData.push({ moment, timestamp, data: cell });
    timestamp += interval * 900000;
  }
  return taggedData;
}
